#include "mytablewidgetitem.h"
#include "ui_mytablewidgetitem.h"
#include "mytcpsocket.h"


MyTableWidgetItem::MyTableWidgetItem(st_friendData fdata, QWidget *parent):
    QWidget(parent),
    ui(new Ui::MyTableWidgetItem)
{
     ui->setupUi(this);

     QString hname = QString("%1.png").arg(fdata.dd_num);
     QString head_url = QString("%1/%2").arg(PATH_IMG).arg(hname);

     int borderWidth = 8; // 边框的宽度
     cv::Scalar borderColor(0, 0, 0, 255);
     QPixmap head = RoundBorderPixmap(downLoadFromUrl(head_url),borderWidth,borderColor);

     ui->stackedWidget->setCurrentWidget(ui->page_friend);
     ui->le_head->setPixmap(head);
     ui->le_nick->setText(fdata.nick);
     ui->le_sex->setText(fdata.sex);
     id = fdata.dd_num;

}

MyTableWidgetItem::MyTableWidgetItem(st_gData gdata, QWidget *parent):
    QWidget(parent),
    ui(new Ui::MyTableWidgetItem)
{
    ui->setupUi(this);

    QString gname = QString("%1.png").arg(gdata.gid);
    QString icon_url = QString("%1/%2").arg(PATH_IMG).arg(gname);

    int borderWidth = 8; // 边框的宽度
    cv::Scalar borderColor(0, 0, 0, 255);
    QPixmap ghead = RoundBorderPixmap(downLoadFromUrl(icon_url),borderWidth,borderColor);

    ui->stackedWidget->setCurrentWidget(ui->page_group);
    ui->le_gicon->setPixmap(ghead);
    ui->le_gname->setText(gdata.gname);
    id = gdata.gid;
}


MyTableWidgetItem::~MyTableWidgetItem()
{
    delete ui;
}

void MyTableWidgetItem::on_btn_add_clicked()
{
    //获取自己的uid
    int uid = GlobalObject::getGlobalObject()->getUserInfo().sdata.dd_num;
    //封装添加好友请求
    QVariantMap map;
    map["cmd"]="add_friend";
    map["user"]=uid;
    map["friend"]=id;

    //发送请求
    GlobalObject::getGlobalObject()->sendRequest(map);
}


void MyTableWidgetItem::on_btn_addgroup_clicked()
{
    //获取自己的uid
    int uid = GlobalObject::getGlobalObject()->getUserInfo().sdata.dd_num;
    //封装添加群聊请求
    QVariantMap map;
    map["cmd"]="add_group";
    map["uid"]=uid;
    map["gid"]=id;

    //发送请求
    GlobalObject::getGlobalObject()->sendRequest(map);
}

